<?php

use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $list \common\models\Awards[] */
$this->title = '马拉松大抽奖';
?>
<section class="page-section prize-step3">
    <div class="prize-header">
        <h2>马拉松大抽奖</h2>
    </div>
    <div class="prize-step3-form">
        <div class="prize-form-control">
            <label for="">姓名：</label>
            <input type="text" name="name" placeholder="请输入姓名">
        </div>
        <div class="prize-form-control">
            <label for="">手机号：</label>
            <input type="tel" name="tel" placeholder="请输入手机号：">
        </div>
        <div class="prize-form-control">
            <label for="">号码牌：</label>
            <input type="text" name="num" placeholder="请输入号码牌">
        </div>
    </div>
    <div class="prize-step3-button">
        <a class="prize-btn prize-btn-submit">确认信息，抽奖</a>
    </div>
</section>

<script src="js/jquery.min.js"></script>
<script>

    $('.prize-btn').on('click', function(){
        var name = $('input[name="name"]').val();
        var tels = $('input[name="tel"]').val();
        var nums = $('input[name="num"]').val();

        if (name == '') {
            alert('请填写姓名');
            return false;
        } else if ( tels == '' || tels.length != 11 ) {
            alert('请填写电话');
            return false;
        } else if ( nums == '' ) {
            alert('请填写号码牌');
            return false;
        }

        var _csrf = '<?= Yii::$app->request->csrfToken ?>';
        $.post('/index.php?r=prize/form', {name: name, tel: tels, num: nums, "_csrf-frontend": _csrf}, function(data){
            if (data.status === 'n')  {
                alert(data.msg);
            } else {
                window.location.href = '/index.php?r=prize/scraping&id=' + data.data.id;
            }

        }, 'json');

    })

</script>
